<template>
  <div class="container">
    <div style="display:flex;justify-content:flex-start;align-items:center;">
      <span>这里用来随机一张淘宝买家秀</span>
      <el-select v-model="selectVal" placeholder="请选择图片来源" style="margin-left:20px;">
        <el-option
          v-for="item in selectList"
          :key="item.label"
          :label="item.label"
          :value="item.label">
        </el-option>
      </el-select>
      <el-button type="primary" style="margin-left:20px;" @click="action">随机</el-button>
    </div>
    <div class="demo-image__preview" style="margin-top:20px">
      <el-image
        style="width: 500px; height: 500px"
        :src="imageUrl"
        :preview-src-list="imageUrlList"
        :fit="'scale-down'">
        <div slot="error" class="image-slot">
          <i class="el-icon-picture-outline"></i>
        </div>
      </el-image>
    </div>
  </div>
</template>

<script>

import { randomBuyerShow,randomBuyerShow2 } from '@/common/common'

export default {
  data() {
    return {
      selectList:[
        {label:"胖次猫"},
        {label:"七了个三"},
        {label:"其他随机"},
      ],
      selectVal:"",
      imageUrl:'',
      imageUrlList:[]
    }
  },
  methods:{
    action(){
      if(this.selectVal == ''){
        this.$message.error("请先选择图片来源");
        return;
      }
      if(this.selectVal == '其他随机'){
        let params = {};
        randomBuyerShow2(params).then(res=>{
          if(res.status == 200) {
            let content = JSON.parse(res.data.body);
            this.imageUrl = content.pic_url;
            this.imageUrlList = [content.pic_url]
          }
        })
      }else {
        let params = {
          type:this.selectVal
        };
        randomBuyerShow(params).then((res) => {
          if(res.status == 200){
            let content = JSON.parse(res.data.body);
            this.imageUrl = content.imgurl;
            this.imageUrlList = [content.imgurl]
          }
        })
        .catch((err) => {
          console.log(err);
        })
      }
    }
  }
}
</script>

<style>
.container {
  width: 100%;
  padding: 1%;
  margin: 0 auto;
}

</style>

<style>
#playMusic {
  display: flex;
  align-items: center;
  margin-top:10px
}
.el-button {
  margin-right: 15px;
}
.slider {
  width: 150px;
  margin-right: 15px;
}
#playMusic > span:nth-of-type(2) {
  margin-left: 5px;
}
</style>
